using System;
using System.IO;

using Gtk;

using Dashboard;
using Dashboard.Util;
using Dashboard.Mint.Widgets;

namespace Dashboard.Mint.Tiles
{
	[Tile (Type = "db:location")]
	public class LocationTile : Tile
	{
		public LocationTile (Match match) : base (match)
		{
			double lat = Double.Parse (match.Properties ["db:latitude"].Value);
			double lng = Double.Parse (match.Properties ["db:longitude"].Value);

			Map map = new Map (160, 80);
			map.AddPoint (match.Properties ["db:city"].Value, lat, lng);

			VBox vbox = new VBox (false, 5);
			
			Label label = new Label ();
			label.Xalign = 0.0f;
			label.Markup = "<b>" + match.Properties ["db:city"].Value + "</b>";
			vbox.PackStart (label, false, true, 0);

			label = new Label ();
			label.Xalign = 0.0f;
			label.Markup = match.Properties ["db:region"].Value;
			vbox.PackStart (label, false, true, 0);

			label = new Label ();
			label.Xalign = 0.0f;
			label.Markup = match.Properties ["db:country"].Value + " (" + match.Properties ["db:code"].Value + ")";
			vbox.PackStart (label, false, true, 0);

			string airport_name = match.Properties ["db:airportname"].Value;
			string airport_city = match.Properties ["db:airportcity"].Value;
			double airport_distance = Double.Parse (match.Properties ["db:airportdistance"].Value);
			string airport_nice = String.Format ("{0} ({1}, {2:0.00}km)", airport_name, airport_city, airport_distance);

			label = new Label ();
			label.Xalign = 0.0f;
			label.Markup = "Nearest airport: " +  airport_nice;
			vbox.PackStart (label, false, true, 0);

			HBox hbox = new HBox (false, 5);
			hbox.BorderWidth = 4;
			hbox.PackStart (map, false, true, 0);
			hbox.PackStart (vbox, true, true, 0);

			//Add (hbox);
		}

		public override Gdk.Pixbuf GetIcon (int size)
		{
			return null;
		}
	}
}